
const demo1 = () => {
  let obj = {};

  // get/set 和 value/writable 不能同时存在
  Object.defineProperty(obj, 'name', {
    configurable: true,
    enumerable: true,
    // writable: true,
    // value: 'lynn hung',
    get() {
      console.log('get');
    },
    set(newVal) {
      console.log('old val: ' + this.value + ' , new val: ' + newVal);
    }
  });
  obj.name = 'lynn hung '
  console.log(obj.name)
}

const demo2 = () => {
  let obj1 = {};
  obj1.name = 'obj1';

  let obj2 = new Object();
  obj2.name = 'obj2';

  let obj3 = Object.create({});
  obj3.name = 'obj3';

  let obj4 = Object.create(Object.prototype);
  obj3.name = 'obj4';

  console.log(Object.getPrototypeOf(obj1)); // [Object: null prototype] {}
  console.log(Object.getPrototypeOf(obj2)); // [Object: null prototype] {}
  console.log(Object.getPrototypeOf(obj3)); // {}
  console.log(Object.getPrototypeOf(obj4)); // [Object: null prototype] {}

  console.log(obj1 instanceof Object);
  console.log(obj2 instanceof Object);
  console.log(obj3 instanceof Object);
  console.log(obj4 instanceof Object);

  // 字面量创建和new关键字创建本质上没有区别，创建的新对象的__proto__都指向Object.prototype。 但字面量创建更高效一些，少了__proto__指向赋值和this
  // Object.create(arg, pro)创建的对象的原型取决于arg，arg为null，新对象是空对象，没有原型，不继承任何对象

}

demo2();
